package com.example.demo.com.task;

import com.example.demo.com.crawler.pojo.News;
import com.example.demo.com.crawler.service.INewsService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * <h3>springboot-webmagic</h3>
 * <p></p>
 *
 * @author : 你的名字
 * @date : 2020-05-13 15:11
 **/
@Component
public class SpringDataPipeline implements Pipeline {
    @Autowired
    private INewsService newsService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        News news = resultItems.get("infos");
        System.out.println("数据2" + news);
        if (news != null) {
            System.out.println("=====");
            //如果不为空存入数据库中
            newsService.save(news);
        }
    }
}
